package com.yksj.healthtalk.ui.login;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.net.http.AsyncHttpResponseHandler;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.utils.ToastUtil;

/**
 * 密码重置
 * @author jack_tang
 *
 */
public class ResetPaswdActivity extends BaseFragmentActivity implements OnClickListener{
	EditText mNumberEditText;
	EditText mPaswdEditText;
	EditText mrepedEditText;
	
	String mDuomeiNum;
	String mAuthCode;
	
	@Override
	protected void onCreate(Bundle arg0) {
		setContentView(R.layout.reset_passwd_layout);
		super.onCreate(arg0);
		
		initUI();
		
		mDuomeiNum = getIntent().getStringExtra("duomei_num");
		mAuthCode = getIntent().getStringExtra("auth_code");
	}
	
	private void initUI(){
		titleLeftBtn.setOnClickListener(this);
		mNumberEditText = (EditText)findViewById(R.id.login_number);
		mNumberEditText.setEnabled(false);
		mNumberEditText.setText(mDuomeiNum);
		
		mPaswdEditText = (EditText)findViewById(R.id.login_password);
		mrepedEditText = (EditText)findViewById(R.id.login_pasw_reped);
		findViewById(R.id.sure_btn).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.sure_btn:
			onComplete();
			break;
		case R.id.title_back:
			onBackPressed();
			break;
		}
	}
	
	private void onComplete(){
		String passwd = mPaswdEditText.getText().toString();
		String repedPasswd = mrepedEditText.getText().toString();
		if(passwd.length() < 6 || passwd.length() > 12){
			mPaswdEditText.setError(getString(R.string.passwd_format_error));
			return;
		}
		
		if(!passwd.equals(repedPasswd)){
			ToastUtil.showShort(this,getString(R.string.passwd_not_same));
			return;
		}
		
		HttpRestClient.doHttpResetPasswd(mDuomeiNum,mAuthCode,passwd,new AsyncHttpResponseHandler(this){
			@Override
			public void onSuccess(int statusCode, String content) {
				if ("1".equals(content)) {
				}
			}
		});
	}
	
	
}
